<?php
/**
 * @package		Tamer
 * @author		Dennis T Kaplan
 * @copyright	Copyright (c) 2008, Tamer, LLC
 * @license		http://zend.pzzazz.com/license.html
 * @link		http://zend.pzzazz.com
 * @since		Version 1.0
 * @filesource
 */

// ------------------------------------------------------------------------

/**
 * Tamer URL Library
 *
 * @package		Tamer
 * @subpackage	Helpers
 * @category	Helpers
 * @author		Dennis T Kaplan
 * @link		http://zend.Tamer.com
 */

 /**
 * Anchor Link
 *
 * Creates an anchor based on the local URL.
 *
 * @access	public
 * @param	string	the URL
 * @param	string	the link title
 * @param	mixed	any attributes
 * @return	string
 */
# example echo anchor('index','Home', array('title' => 'The best WebSite!'));
function anchor($uri = '', $title = '', $attributes = '')
{
	$title = (string) $title;
	
	if ( ! is_array($uri))
	{
		$site_url = ( ! preg_match('!^\w+://!i', $uri)) ? BASEURL.$uri : $uri;
	}
	else
	{
		$site_url = BASEURL.$uri;
	}
	
	if ($title == '')
	{
		$title = $uri;
	}

	if ($attributes == '')
	{
		$attributes = ' title="'.$title.'"';
	}
	else
	{
		$attributes = _parse_attributes($attributes);
	}

	return '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>';
}

/**
 * Parse out the attributes
 *
 * Some of the functions use this
 *
 * @access	private
 * @param	array
 * @param	bool
 * @return	string
 */
function _parse_attributes($attributes, $javascript = FALSE)
{
	if (is_string($attributes))
	{
		return ($attributes != '') ? ' '.$attributes : '';
	}

	$att = '';
	foreach ($attributes as $key => $val)
	{
		if ($javascript == TRUE)
		{
			$att .= $key . '=' . $val . ',';
		}
		else
		{
			$att .= ' ' . $key . '="' . $val . '"';
		}
	}
	
	if ($javascript == TRUE AND $att != '')
	{
		$att = substr($att, 0, -1);
	}
	
	return $att;
}

?>
